//
//  WifiListModel.m
//
//  Created by Xuanyi  on 15/6/29
//  Copyright (c) 2015 __MyCompanyName__. All rights reserved.
//

#import "WifiListModel.h"


NSString *const kWifiListModelExtCH = @"ExtCH";
NSString *const kWifiListModelWMode = @"W_Mode";
NSString *const kWifiListModelSiganl = @"Siganl";
NSString *const kWifiListModelNT = @"NT";
NSString *const kWifiListModelBSSID = @"BSSID";
NSString *const kWifiListModelSecurity = @"Security";
NSString *const kWifiListModelSSID = @"SSID";
NSString *const kWifiListModelWPS = @"WPS";
NSString *const kWifiListModelCh = @"Ch";


@interface WifiListModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation WifiListModel

@synthesize extCH = _extCH;
@synthesize wMode = _wMode;
@synthesize siganl = _siganl;
@synthesize nT = _nT;
@synthesize bSSID = _bSSID;
@synthesize security = _security;
@synthesize sSID = _sSID;
@synthesize wPS = _wPS;
@synthesize ch = _ch;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.extCH = [self objectOrNilForKey:kWifiListModelExtCH fromDictionary:dict];
            self.wMode = [self objectOrNilForKey:kWifiListModelWMode fromDictionary:dict];
            self.siganl = [self objectOrNilForKey:kWifiListModelSiganl fromDictionary:dict];
            self.nT = [self objectOrNilForKey:kWifiListModelNT fromDictionary:dict];
            self.bSSID = [self objectOrNilForKey:kWifiListModelBSSID fromDictionary:dict];
            self.security = [self objectOrNilForKey:kWifiListModelSecurity fromDictionary:dict];
            self.sSID = [self objectOrNilForKey:kWifiListModelSSID fromDictionary:dict];
            self.wPS = [self objectOrNilForKey:kWifiListModelWPS fromDictionary:dict];
            self.ch = [self objectOrNilForKey:kWifiListModelCh fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:self.extCH forKey:kWifiListModelExtCH];
    [mutableDict setValue:self.wMode forKey:kWifiListModelWMode];
    [mutableDict setValue:self.siganl forKey:kWifiListModelSiganl];
    [mutableDict setValue:self.nT forKey:kWifiListModelNT];
    [mutableDict setValue:self.bSSID forKey:kWifiListModelBSSID];
    [mutableDict setValue:self.security forKey:kWifiListModelSecurity];
    [mutableDict setValue:self.sSID forKey:kWifiListModelSSID];
    [mutableDict setValue:self.wPS forKey:kWifiListModelWPS];
    [mutableDict setValue:self.ch forKey:kWifiListModelCh];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.extCH = [aDecoder decodeObjectForKey:kWifiListModelExtCH];
    self.wMode = [aDecoder decodeObjectForKey:kWifiListModelWMode];
    self.siganl = [aDecoder decodeObjectForKey:kWifiListModelSiganl];
    self.nT = [aDecoder decodeObjectForKey:kWifiListModelNT];
    self.bSSID = [aDecoder decodeObjectForKey:kWifiListModelBSSID];
    self.security = [aDecoder decodeObjectForKey:kWifiListModelSecurity];
    self.sSID = [aDecoder decodeObjectForKey:kWifiListModelSSID];
    self.wPS = [aDecoder decodeObjectForKey:kWifiListModelWPS];
    self.ch = [aDecoder decodeObjectForKey:kWifiListModelCh];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_extCH forKey:kWifiListModelExtCH];
    [aCoder encodeObject:_wMode forKey:kWifiListModelWMode];
    [aCoder encodeObject:_siganl forKey:kWifiListModelSiganl];
    [aCoder encodeObject:_nT forKey:kWifiListModelNT];
    [aCoder encodeObject:_bSSID forKey:kWifiListModelBSSID];
    [aCoder encodeObject:_security forKey:kWifiListModelSecurity];
    [aCoder encodeObject:_sSID forKey:kWifiListModelSSID];
    [aCoder encodeObject:_wPS forKey:kWifiListModelWPS];
    [aCoder encodeObject:_ch forKey:kWifiListModelCh];
}

- (id)copyWithZone:(NSZone *)zone
{
    WifiListModel *copy = [[WifiListModel alloc] init];
    
    if (copy) {

        copy.extCH = [self.extCH copyWithZone:zone];
        copy.wMode = [self.wMode copyWithZone:zone];
        copy.siganl = [self.siganl copyWithZone:zone];
        copy.nT = [self.nT copyWithZone:zone];
        copy.bSSID = [self.bSSID copyWithZone:zone];
        copy.security = [self.security copyWithZone:zone];
        copy.sSID = [self.sSID copyWithZone:zone];
        copy.wPS = [self.wPS copyWithZone:zone];
        copy.ch = [self.ch copyWithZone:zone];
    }
    
    return copy;
}


@end
